package game.block.tutorial;

import java.util.ArrayList;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.NinePatch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;

public class Tutorial {
    public static float TUTORIAL_TIME = 5;
    public static float TUTORIAL_X = 0.02F;
    public static float TUTORIAL_Y = 0.98F;
    public static float TUTORIAL_WRAP = 0.3F;
    private NinePatch patch;
    protected TextButton button;
    private BitmapFont font;
    protected TextButtonStyle style;
    protected boolean done;
    private ArrayList<ArrayList<String>> strings;
    private int tutorialNum;
    private int index;

    public Tutorial() {
        index = 0;
        font = new BitmapFont(Gdx.files.internal("data/white.fnt"), false);
        patch = new NinePatch(new Texture(Gdx.files.internal("data/art/textBack.png")));
        NinePatchDrawable npd = new NinePatchDrawable(patch);
        style = new TextButtonStyle();
        style.font = font;
        done = false;
        style.up = npd;
        strings = new ArrayList<ArrayList<String>>();
        ArrayList<String> tutorial = new ArrayList<String>();

        tutorial.add("Move the king block by touching it, then touching an open green space"); // tutorial 1
        tutorial.add("Move it to the goal");
        strings.add(tutorial);
        tutorial = new ArrayList<String>();

        tutorial.add("Other blocks are movable such as the light blue basic block"); // tutorial 2
        tutorial.add("Move it into the quicksand trap");
        strings.add(tutorial);
        tutorial = new ArrayList<String>();

        tutorial.add("Place blocks next to jump blocks. This will give them the ability to jump a square"); // tutorial
        strings.add(tutorial);
        tutorial = new ArrayList<String>();

        tutorial.add("Spikes alternate every turn"); // tutorial
        tutorial.add("Blocks placed on a spike trap for multiple turns will not destroy the block");
        strings.add(tutorial);
        tutorial = new ArrayList<String>();

        tutorial.add("Stone blocks are not affected by fire"); // tutorial 5
        tutorial.add("Move the stone block in front of the fire to obstruct it");
        strings.add(tutorial);
        tutorial = new ArrayList<String>();

        tutorial.add("Stone blocks can also obstruct wind"); // tutorial 6
        strings.add(tutorial);
        tutorial = new ArrayList<String>();

        tutorial.add("Blocks slide on ice"); // tutorial 7
        tutorial.add("Luckily, the traction block does not");
        strings.add(tutorial);
        tutorial = new ArrayList<String>();

        tutorial.add("Explosion blocks can destroy a wall"); // tutorial 8
        strings.add(tutorial);
        tutorial = new ArrayList<String>();

    }

    public void pickLevel(int l) {
        tutorialNum = l-1;
        index = 0;
    }

    public void render(BitmapFont font, SpriteBatch sb) {
        if (strings.size() > tutorialNum) { //draw tutorial box
            patch.draw(sb, Gdx.graphics.getWidth() * 0.0f, Gdx.graphics.getHeight() * 0.8f, Gdx.graphics.getWidth() * 0.35f,
                    Gdx.graphics.getHeight() * 0.2f);

            if (strings.get(tutorialNum).size() > index) {  //draw tutorial message
                font.drawWrapped(sb, "Tutorial:\n"+strings.get(tutorialNum).get(index), Gdx.graphics.getWidth() * TUTORIAL_X,
                        Gdx.graphics.getHeight() * TUTORIAL_Y, Gdx.graphics.getWidth() * TUTORIAL_WRAP);
            } else {    //draw last tutorial message if there isn't a new one
                font.drawWrapped(sb, strings.get(tutorialNum).get(index - 1), Gdx.graphics.getWidth() * TUTORIAL_X, Gdx.graphics.getHeight()
                        * TUTORIAL_Y, Gdx.graphics.getWidth() * TUTORIAL_WRAP);
            }
        }

    }
    
    public boolean hasMultiplieTutorials(){
    	return strings.get(tutorialNum).size() > 1;
    }
    
    public void previous(){
    	index=Math.min(0, index--);
    }
    
    public void next(){
    	index=Math.max(strings.get(tutorialNum).size()-1, index++);
    }
    
    public boolean hasTutorial(){
    	return strings.size() > (tutorialNum + 1);
    }

    public void update(float delta) {
/*        messageTimer += delta;
        if (strings.size() > tutorialNum && messageTimer > TUTORIAL_TIME && strings.get(tutorialNum).size() < index) {
            index++;
            messageTimer = 0;
        }*/
    }
}
